import {
  RECEIVE_WAY_MAP,
  RULE_CONFIG_STATE_MAP,
  RULE_CONFIG_STATE_OFF,
  RULE_CONFIG_STATE_ON,
  SEND_STATE_MAP,
  TRIGGER_CONDITION_MAP,
  RULE_GROUP_STATUS_UN_SUBMIT,
  RULE_GROUP_STATUS_EXPIRED,
  ADDRESS_GROUP_STATE_MAP,
  ADDRESS_GROUP_STATE_DRAFT
} from './const.js'

export function RemindRecordLists() {
  return [
    {
      title: '规则组名称',
      key: 'ruleGroupName'
    },
    {
      title: '领域',
      key: 'reportName',
      width: 300

    },
    {
      title: '触发条件',
      key: 'triggerCondition',
      width: 300,
      render: (h, params) => {
        return h('span', TRIGGER_CONDITION_MAP[params.row.triggerCondition] || '')
      }
    },
    {
      title: '触发时间',
      key: 'triggerTime'
    },
    {
      title: '接收人',
      key: 'receivers',
      width: 100
    },

    {
      title: '发送时间',
      key: 'createTime'
    },
    {
      title: '发送状态',
      key: 'state',
      width: 100,
      render: (h, params) => {
        return h('span', SEND_STATE_MAP[params.row.state] || '')
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 70,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '详情',
                handle: () => {
                  this.goDetail(params.row)
                }
              }
            ]
          }
        })
      }
    },
  ]
}

export function AddressGroupLists() {
  const self = this
  const _getSubmitHidden = function(params) {
    return params.row.validFlag != ADDRESS_GROUP_STATE_DRAFT
  }
  return [
    {
      title: '领域',
      key: 'reportName'
    },
    {
      title: '单位名称',
      key: 'trgNode'
      // width: 300,

    },
    {
      title: '收件人组名',
      key: 'groupName'
      // width: 200,

    },
    // {
    //   title: '报表类型',
    //   key: 'reportType'
    // },
    // {
    //   title: '报表名称',
    //   key: 'reportName'
    // },
    {
      title: '收件人',
      key: 'receiver'
      // width: 300,
    },
    {
      title: '创建人',
      key: 'createName'
      // width: 300,
    },
    {
      title: '创建时间',
      key: 'createTime',
      width: 170
    },
    {
      title: '状态',
      key: 'validFlag',
      render: (h, params) => {
        return h('span', ADDRESS_GROUP_STATE_MAP[params.row.validFlag] || '')
      },
      width: 100
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 160,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '提交',
                hidden: _getSubmitHidden(params, self),
                handle: () => {
                  this.goAddressGroupSubmit(params.row)
                }
              },
              {
                type: 'text',
                text: '详情',
                handle: () => {
                  this.goAddressGroupDetail(params.row)
                }
              },
              {
                type: 'text',
                text: '编辑',
                handle: () => {
                  this.goAddressGroupEdit(params.row)
                }
              },
              {
                type: 'text',
                text: '删除',
                handle: () => {
                  this.deleteAddressGroup(params.row)
                }
              }
            ]
          }
        })
      }
    },
  ]
}

export function ruleConfigColumns() {
  let getStartOrCloseName = function(state) {
    if (state == RULE_CONFIG_STATE_ON) {
      return '关闭'
    } else if (state == RULE_CONFIG_STATE_OFF) {
      return '开启'
    } else {
      return '开启'
    }
  }
  return [
    {
      title: '规则名称',
      key: 'ruleName'
    },
    {
      title: '报表名称',
      key: 'reportName'
    },
    {
      title: '接收人',
      key: 'receiver'
    },
    {
      title: '创建人',
      key: 'sponsor',
      width: 150
    },
    {
      title: '更新时间',
      key: 'updateTime'
    },
    {
      title: '状态',
      key: 'state',
      render: (h, params) => {
        return h('span', RULE_CONFIG_STATE_MAP[params.row.state] || '')
      },
      width: 100
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 130,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '详情',
                handle: () => {
                  this.goDetail(params.row)
                }
              },
              {
                type: 'text',
                text: '编辑',
                handle: () => {
                  this.goEdit(params.row)
                }
              },
              {
                type: 'text',
                text: getStartOrCloseName(params.row.state),
                handle: () => {
                  this.startOrStopRule(params.row)
                }
              },
              {
                type: 'text',
                text: '删除',
                hidden: params.row.state == RULE_CONFIG_STATE_ON,
                handle: () => {
                  this.goDelete(params.row)
                }
              }
            ]
          }
        })
      }
    },
  ]
}

export function ruleConfigColumns2() {
  const self = this
  const _getSubmitHidden = function(params) {
    return params.row.ruleGroupStatusCode != RULE_GROUP_STATUS_UN_SUBMIT
  }
  const _getEditHidden = function(params) {
    return params.row.ruleGroupStatusCode == RULE_GROUP_STATUS_EXPIRED
  }
  return [
    {
      title: '规则组名称',
      key: 'ruleGroupName'
    },
    {
      title: '领域',
      key: 'reportName'
    },
    {
      title: '更新时间',
      key: 'updateTime'
    },
    {
      title: '状态',
      key: 'ruleGroupStatus',
      width: 100
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 160,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '提交',
                hidden: _getSubmitHidden(params, self),
                handle: () => {
                  this.goSubmit(params.row)
                }
              },
              {
                type: 'text',
                text: '详情',
                handle: () => {
                  this.goDetail(params.row)
                }
              },
              {
                type: 'text',
                text: '编辑',
                hidden: _getEditHidden(params, self),
                handle: () => {
                  this.goEdit(params.row)
                }
              },
              {
                type: 'text',
                text: '删除',
                handle: () => {
                  this.goDelete(params.row)
                }
              }
            ]
          }
        })
      }
    },
  ]
}

// 收件人组
export const columnListAddressGroup = [
  { columnName: '领域', columnKey: 'reportName' },
  { columnName: '单位名称', columnKey: 'trgNode', disabled: true },
  { columnName: '收件人组名', columnKey: 'groupName', disabled: true },
  // { columnName: '报表类型', columnKey: 'reportType' },
  // { columnName: '报表名称', columnKey: 'reportName' },
  // { columnName: '所属二级组织', columnKey: 'company' },
  { columnName: '收件人', columnKey: 'receiver', disabled: true },
  { columnName: '抄送人', columnKey: 'ccs' },
  { columnName: '创建人', columnKey: 'createName' },
  { columnName: '创建时间', columnKey: 'createTime' },
  { columnName: '更新时间', columnKey: 'updateTime' },
  {
    columnName: '状态', columnKey: 'validFlag', render: (h, params) => {
      return h('span', ADDRESS_GROUP_STATE_MAP[params.row.validFlag] || '')
    }
  }
]

// 提醒记录
export const columnListRemindRecord = [
  { columnName: '规则组名称', columnKey: 'ruleGroupName', disabled: true },
  { columnName: '报表类型', columnKey: 'reportType' },
  { columnName: '领域', columnKey: 'reportName', disabled: true },
  {
    columnName: '触发条件', columnKey: 'triggerCondition', render: (h, params) => {
      return h('span', TRIGGER_CONDITION_MAP[params.row.triggerCondition] || '')
    }
  },
  { columnName: '触发时间', columnKey: 'triggerTime' },
  {
    columnName: '接收方式', columnKey: 'remindWay', minWidth: 100, render: (h, params) => {
      return h('span', RECEIVE_WAY_MAP[params.row.remindWay] || '')
    }
  },
  { columnName: '接收人', columnKey: 'receiver' },
  { columnName: '邮件主题', columnKey: 'mailTitle' },
  { columnName: '提醒内容', columnKey: 'content' },
  { columnName: '发送时间', columnKey: 'createTime' },
  {
    columnName: '发送状态', columnKey: 'state', disabled: true, render: (h, params) => {
      return h('span', SEND_STATE_MAP[params.row.state] || '')
    }
  }
]

// 规则配置
export const columnListRuleConfig = [
  { columnName: '规则名称', columnKey: 'ruleName', disabled: true },
  { columnName: '报表类型', columnKey: 'reportType' },
  { columnName: '报表名称', columnKey: 'reportName', disabled: true },
  {
    columnName: '触发条件', columnKey: 'triggerCondition', render: (h, params) => {
      return h('span', TRIGGER_CONDITION_MAP[params.row.triggerCondition] || '')
    }
  },
  { columnName: '填报季度/年度', columnKey: 'reportTime'},
  {
    columnName: '接收方式', columnKey: 'receiveWay', render: (h, params) => {
      return h('span', RECEIVE_WAY_MAP[params.row.receiveWay] || '')
    }
  },
  { columnName: '接收人', columnKey: 'receivers' },
  { columnName: '邮件主题', columnKey: 'mailTitle' },
  { columnName: '邮件内容', columnKey: 'context' },
  { columnName: '创建人', columnKey: 'sponsor' },
  { columnName: '创建时间', columnKey: 'createTime' },
  { columnName: '更新时间', columnKey: 'updateTime' },
  {
    columnName: '状态', columnKey: 'state', disabled: true, render: (h, params) => {
      return h('span', RULE_CONFIG_STATE_MAP[params.row.state] || '')
    }
  }
]
